package com.eascs.ticket.ticket.controller;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eascs.ticket.common.controller.BaseMasterViewController;
import com.eascs.ticket.configuration.entity.Attachment;
import com.eascs.ticket.configuration.service.AttachmentService;
import com.eascs.ticket.ticket.entity.TicketAttachment;
import com.eascs.ticket.ticket.form.ViewTicketAttachmentForm;
import com.eascs.ticket.ticket.service.TicketAttachmentService;
import com.eascs.web.exception.RedirectException;

@Controller
public class TicketAttachmentViewController extends BaseMasterViewController {
	@Inject
	private TicketAttachmentService ticketAttachmentService;

	@Inject
	private AttachmentService attachmentService;

	@RequestMapping("/ticket/viewTicketAttachment")
	public String viewTicketAttachment(ViewTicketAttachmentForm viewTicketAttachmentForm) {
		TicketAttachment ticketAttachment = ticketAttachmentService.getTicketAttachmentById(viewTicketAttachmentForm.getId());
		Attachment attachment = attachmentService.getAttachmentById(ticketAttachment.getAttachmentId());
		throw new RedirectException(attachment.getViewUrl());
	}

}
